package servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author MissChen
 * @date 2024年04月23日 16:03
 */
@WebServlet("/method")
public class MethodServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String contextPath=request.getContextPath();
        System.out.println("应用名:"+contextPath);


        //获取访问命令
        //一般情况下,用于获取浏览器地址栏应用名后面的地址,获取的地址相当于是url-pattern的值
        String servletPath=request.getServletPath();
        System.out.println("servletPath:"+servletPath);

        // 获取浏览器地址栏端口号后面的地址
        String uri=request.getRequestURI();
        System.out.println("uri:"+uri);


        // 获取浏览器地址栏完整地址,整个URL地址
        StringBuffer url=request.getRequestURL();
        System.out.println("url:"+url);

        // 获取访问当前服务器的访问者的ip地址
        String ip=request.getRemoteAddr();
        System.out.println("ip:"+ip);
    }
}
